%%
clear;
close all;

% Load data
load('Result_K_6.mat', 'betat_hat', 'qn', 'K', 'H', 'Delta_n');
bb = mean(betat_hat, 3);

% Load factor names
load('../Data/factors.mat');
factors_name{3} = {'MKT'};

% Create a figure
figure;

% Loop through the factors and create subplots for each
for i = 1:6
    % First plot: bb(:,i) vs bb(:,6+2*i-1)
    subplot(6, 3, 3*(i-1)+1);
    plot(bb(:,i), bb(:,6 + 2*i - 1), 'ro', 'MarkerSize', 5); 
    hold on;
    plot(bb(:,i), bb(:,i), 'b:', 'LineWidth', 1);
    
    % Linear regression line in black
    p = polyfit(bb(:,i), bb(:,6 + 2*i - 1), 1);
    yfit = polyval(p, bb(:,i));
    plot(bb(:,i), yfit, 'k-', 'LineWidth', 1.5);  % Black regression line

    title(factors_name{2 + i}, 'FontSize', 12);
    xlabel('Cont. Beta', 'FontSize', 10);
    ylabel('Neg. Jump Beta', 'FontSize', 10);
    axis tight;
    grid on;

    % Second plot: bb(:,i) vs bb(:,6+2*i)
    subplot(6, 3, 3*(i-1)+2);
    plot(bb(:,i), bb(:,6 + 2*i), 'ro', 'MarkerSize', 5);
    hold on;
    plot(bb(:,i), bb(:,i), 'b:', 'LineWidth', 1);
    
    % Linear regression line in black
    p = polyfit(bb(:,i), bb(:,6 + 2*i), 1);
    yfit = polyval(p, bb(:,i));
    plot(bb(:,i), yfit, 'k-', 'LineWidth', 1.5);  % Black regression line

    title(factors_name{2 + i}, 'FontSize', 12);
    xlabel('Cont. Beta', 'FontSize', 10);
    ylabel('Pos. Jump Beta', 'FontSize', 10);
    axis tight;
    grid on;

    % Third plot: bb(:,6+2*i-1) vs bb(:,6+2*i)
    subplot(6, 3, 3*(i-1)+3);
    plot(bb(:,6 + 2*i - 1), bb(:,6 + 2*i), 'ro', 'MarkerSize', 5);
    hold on;
    plot(bb(:,6 + 2*i - 1), bb(:,6 + 2*i - 1), 'b:', 'LineWidth', 1);
    
    % Linear regression line in black
    p = polyfit(bb(:,6 + 2*i - 1), bb(:,6 + 2*i), 1);
    yfit = polyval(p, bb(:,6 + 2*i - 1));
    plot(bb(:,6 + 2*i - 1), yfit, 'k-', 'LineWidth', 1.5);  % Black regression line

    title(factors_name{2 + i}, 'FontSize', 12);
    xlabel('Neg. Jump Beta', 'FontSize', 10);
    ylabel('Pos. Jump Beta', 'FontSize', 10);
    axis tight;
    grid on;

end

% Set the figure background to white for a cleaner look
set(gcf, 'Color', 'w');

